<?php
    // +----------------------------------------------------------------------
    // | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ] 
    // +----------------------------------------------------------------------
    // | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
    // +----------------------------------------------------------------------
    // | SiteUrl: http://www.luckyhhy.cn
    // +----------------------------------------------------------------------
    // | Author: LuckyHhy <jackhhy520@qq.com>
    // +----------------------------------------------------------------------
    // | Date: 2020/3/17-16:46
    // +----------------------------------------------------------------------
    // | Description:  
    // +----------------------------------------------------------------------


    namespace app\admin\behavior;

    /**
     * Class MyQueueFailedLogger
     * @package app\admin\behavior
     * 这是一个行为类，用于处理所有的消息队列中的任务失败回调
     */
    class MyQueueFailedLogger
    {
        const should_run_hook_callback = true;

        /**
         * @param $jobObject   \think\queue\Job   //任务对象，保存了该任务的执行情况和业务数据
         * @return bool     true                  //是否需要删除任务并触发其failed() 方法
         */
        public function logAllFailedQueues(&$jobObject){

            $failedJobLog = [
                'jobHandlerClassName'   => $jobObject->getName(), // 'application\index\job\Hello'
                'queueName' => $jobObject->getQueue(),			   // 'helloJobQueue'
                'jobData'   => $jobObject->getRawBody()['data'],  // '{'a': 1 }'
                'attempts'  => $jobObject->attempts(),            // 3
            ];
            var_export(json_encode($failedJobLog,true));
            // $jobObject->release();     //重发任务
            //$jobObject->delete();         //删除任务
            //$jobObject->failed();	  //通知消费者类任务执行失败

            return self::should_run_hook_callback;
        }

    }